[DllImport("odbc32.dll",CharSet=CharSet.Ansi)]
static extern short SQLTables(IntPtr StatementHandle,
string CatalogName, short NameLength1,
string SchemaName, short NameLength2,
string TableName, short NameLength3,
string TableType, short NameLength4);
TODO.
// flags for null-terminated string
const short SQL_NTS = (-3);
Do you know one? Please contribute it!
Resulting table has a prefined columns:
string table_cat = cmd.GetFieldValue(1); //database name
string table_schem = cmd.GetFieldValue(2); //table owner
string table_name = cmd.GetFieldValue(3); //table name
string table_type = cmd.GetFieldValue(4); //"TABLE","VIEW" or "SYNONYM"
string remarks = cmd.GetFieldValue(5);
Microsoft access ODBC driver only likes it if the first two parameters are NULL since the tablequalifier and tableowner don't apply to MDB files. Also, SYNONYMs are MSAccess linked tables.
void GetTables()
{
drop();
if (!isOK(SQLAllocStmt(connectionHandle, out statementHandle)))
throw new Exception("Failed to allocate statement.");
if (!isOK(SQLTables(statementHandle,
null,
SQL_NTS,
null,
SQL_NTS,
null,
SQL_NTS,
"TABLE,VIEW,SYNONYM",
SQL_NTS)))
{
throw new Exception(GetError());
}
}
void drop()
{
if (statementHandle.ToInt32()!=0)
{
SQLFreeStmt(statementHandle, SQL_DROP);
}
statementHandle = IntPtr.Zero;
}